{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">

                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.layer_show('添加', '{:url('cateAdd')}');">
                            <i class="fa fa-plus"></i> 添加分类
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <script type="text/html" id="levelBar">
                        {{# if(d.gc_level == 1){ }}
                        {{d.gc_name}}
                        {{# } }}
                        {{# if(d.gc_level == 2){ }}
                        <span style="color: red">&nbsp;&nbsp;&nbsp;|--&nbsp;{{d.gc_name}}</span>
                        {{# } }}
                    </script>

                    <script type="text/html" id="levelBar1">
                        {{# if(d.gc_level == 1){ }}
                        一级分类
                        {{# } }}
                        {{# if(d.gc_level == 2){ }}
                        二级分类
                        {{# } }}
                    </script>


                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.gc_id != 4) { }}
                        {{# if(d.gc_level == 1){ }}
                        <a href="javascript:;" onclick="wk.layer_show('添加', '{:url('cateAdd')}?gc_id={{d.gc_id}}')" class="btn btn-info btn-xs m-r-xs" title="添加子菜单"><i class="fa fa-sitemap">添加子菜单</i></a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.layer_show('编辑', '{:url('cateEdit')}?gc_id={{d.gc_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil">编辑</i></a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.gc_id}}','{:url('cateDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Goodscate/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30, 100]
            , limit: 100
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
                  {type:'numbers', width: 60, title: '序号'}
                , {field: 'gc_name', width: '', title: '分类名称', align: 'left', toolbar: '#levelBar'}
                , {field: 'gc_level', width: 140, title: '分类等级', align: 'center', toolbar: '#levelBar1'}
                , {field: 'gc_sort', width: '', title: '排序(可编辑)', align: 'center', edit: 'test'}
                , {field: 'gc_time', width: '', title: '添加时间', align: 'center'}
                , {fixed: 'right', width: 300, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });

        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            wk.change(data.gc_id,"{:url('updateSort')}",field,value);
        });

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['gc_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>